%Input:
% ts1 and ts2 are two row vectors (time series);
%
%Output:
% l is the length of the largest common subsequence.
% b is used to create the largest common string of the two vectors;

function [l,b]=LCSS(ts1,ts2)

m=size(ts1,2);
n=size(ts2,2);

c=zeros(m+1,n+1);
b=c;

for i=2:m+1
    for j=2:n+1
        if  (substring(ts1,i-2,i-2)==substring(ts2,j-2,j-2))
            c(i,j)=c(i-1,j-1)+1;
            b(i,j)=1;
        elseif (c(i-1,j)>=c(i,j-1))
            c(i,j)=c(i-1,j);
            b(i,j)=2;
        else
            c(i,j)=c(i,j-1);
            b(i,j)=3;
        end
    end
end

l=c(m+1,n+1);

